package com.yzc.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yzc.mapper.TeasingMapper;
import com.yzc.model.entity.teasing.Teasing;
import com.yzc.model.vo.teasing.TeasingVo;
import com.yzc.service.TeasingService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TeasingServiceImpl extends ServiceImpl<TeasingMapper, Teasing> implements TeasingService {

    @Autowired
    private TeasingMapper teasingMapper;


    @Override
    public IPage<TeasingVo> loadAllMessage(Page<Teasing> pageParam) {

        QueryWrapper<Teasing> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_deleted", 0); // 只查询未删除的数据

        IPage<Teasing> page = teasingMapper.selectPage(pageParam, queryWrapper);

        return page.convert(teasing -> {
            TeasingVo vo = new TeasingVo();
            BeanUtils.copyProperties(teasing, vo); // 使用 BeanUtils 进行属性拷贝
            return vo;
        });
    }

    @Override
    public void deleteTeasById(Teasing id) {
        teasingMapper.deleteById(id);
    }
}
